<template>
  <div class="amap-page-container">
    <p>
      文档地址: <a href="https://elemefe.github.io/vue-amap/#/zh-cn/base/amap" target="_blank">https://elemefe.github.io/vue-amap/#/zh-cn/base/amap</a>
    </p>
    <el-amap vid="amap" :zoom="zoom" :center="center" class="amap-demo">
      <el-amap-polyline
        :editable="polyline.editable"
        :path="polyline.path"
        :events="polyline.events"></el-amap-polyline>
    </el-amap>

    <div class="toolbar">
      <a-button name="button" @click="changeEditable">change editable</a-button>
    </div>
  </div>
</template>

<script>
import VueAMap from 'vue-amap'

VueAMap.initAMapApiLoader({
  key: '59ec5ef06b273ce4796c72c130d7116c',
  plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
  v: '1.4.4'
})

export default {
  components: { VueAMap },
  data () {
    return {
      zoom: 12,
      center: [121.5273285, 31.25515044],
      polyline: {
        path: [[121.5389385, 31.21515044], [121.5389385, 31.29615044], [121.5273285, 31.21515044]],
        events: {
          click (e) {
            alert('click polyline')
          },
          end: (e) => {
            const newPath = e.target.getPath().map(point => [point.lng, point.lat])
            console.log(newPath)
          }
        },
        editable: false
      }
    }
  },
  methods: {
    changeEditable () {
      this.polyline.editable = !this.polyline.editable
    }
  }
}
</script>

<style scoped>
  .amap-page-container {
    height: 500px;
  }
</style>
